package cn.itcast.dao.impl;

import cn.itcast.dao.UserDao;
import cn.itcast.domain.User;
import cn.itcast.utils.DataSourceUtil;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jt = new JdbcTemplate(DataSourceUtil.getDataSouce());

    //登录验证
    public User login(String username, String password) {

        User user = null;
        try {
            user = jt.queryForObject("select * from user where username = ? and password = ?", new BeanPropertyRowMapper<User>(User.class), username, password);
        } catch (DataAccessException e) {
            e.printStackTrace();
        }

        return user;


    }

    //查询所有
    public List<User> findAll() {
        List<User> users = jt.query("select * from user ", new BeanPropertyRowMapper<User>(User.class));
        return users;
    }
}
